package com.ruipengkj.model;

import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.ruipengkj.bean.TEmployee;
import com.ruipengkj.bean.TStore;
import com.ruipengkj.bean.TStoreTransfer;
import com.ruipengkj.commons.BuildSpringApplication;
import com.ruipengkj.service.TEmployeeService;
import com.ruipengkj.service.TStoreService;
/**
 * 仓库调拨
 * */
public class StoreTransferModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas=new Vector<List<Object>>();
	private Vector<String> columns = new Vector<String>();
	
	private TStoreService tStoreService;
	private TEmployeeService tEmployeeService;
	
	public StoreTransferModel(){
		tEmployeeService = BuildSpringApplication.getInstance().getTEmployeeServiceImpl();
		tStoreService = BuildSpringApplication.getInstance().getTStoreServiceImpl();
		columns.add("调拨编号");
		columns.add("调出仓库");
		columns.add("调入仓库");
//		columns.add("调拨商品编号");
		columns.add("调拨商品数量");
		columns.add("操作人");
		columns.add("操作时间");
//		columns.add("状态");
//		columns.add("审核人");
//		columns.add("审核时间 ");
	}
	//获得行数
	public int getRowCount(){
		return rowdatas.size();
	}
	//获得列数
	public int getColumnCount(){
		return columns.size();
	}
	//获得单元格的值
	public Object getValueAt(int row,int column){
		
		return ((Vector)rowdatas.get(row)).get(column);
	}
	//获取列名
	public String getColumnName(int column){
		return (String)columns.get(column);
	}
	//设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		return false;
	}
	
	public void removeData(int row){
		rowdatas.remove(row);
	}
	
	//设置单元格的值
	public void setValueAt(Object aValue,int rowIndex,int columnIndex){
		//取出对应的记录
		Vector rowdata = (Vector)rowdatas.get(rowIndex);
		//删除原来的值
		rowdata.remove(columnIndex);
		//添加用户新修改的值
		rowdata.add(columnIndex,aValue);
	}


	public void setRowData(List<TStoreTransfer> tStoreTransferList) {
		rowdatas.clear();
		if(tStoreTransferList!=null&&tStoreTransferList.size()!=0){
			for(int i=0;i<tStoreTransferList.size();i++){
				TStoreTransfer storeTransfer=tStoreTransferList.get(i);
				List<Object> row=new Vector<Object>();
				row.add(storeTransfer.getTransferID());//调拨编号
				
				TStore tStore = null;
				try {
					tStore = tStoreService.getByIdService(storeTransfer.getOutStoreID());
				} catch (Exception e) {
					e.printStackTrace();
				}
				if (tStore != null && tStore.getStoreID() != null) {
					row.add(tStore.getName());//调出仓库
				} else {
					row.add("");
				}
				try {
					tStore = null;
					tStore = tStoreService.getByIdService(storeTransfer.getInStoreID());
				} catch (Exception e) {
					e.printStackTrace();
				}
				if (tStore != null && tStore.getStoreID() != null) {
					row.add(tStore.getName());//调入仓库
				} else {
					row.add("");
				}
				row.add(storeTransfer.getNum());//调拨商品数量
				if (storeTransfer.getOperator() != null) {
				try {
					TEmployee tEmployee = tEmployeeService.getNameByIdService(storeTransfer.getOperator());
					if (tEmployee != null && tEmployee.getName() != null)
						row.add(tEmployee.getName());
					else
						row.add("");
				} catch (Exception e) {
					e.printStackTrace();
				}
				} else 
					row.add("");
				row.add(storeTransfer.getHappenTime());//操作时间
				rowdatas.add(row);
			}
		}
	}

	public void clear(){
		rowdatas.clear();
	}
}
